<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/** Auth loginpage **/
class Auth extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model("users");
	}
	
	function index()
	{
		$value['title']  = "Login";
		$value['content']= "vauth/vlogin";
		$this->load->view('themes/bdo/index',$value);
	}
	
	public function check_login($nik,$password)
	{
		$password = $password;
		if(!$this->users->checkUserLogin($nik,$password))
			return false;
		return true;	
	}
	
	public function do_login()
    {
		$nik      = $this->input->post('nik');
		$password = $this->input->post('password');
		if($this->check_login($nik,$password)):
			$user = $this->users->getUserData($nik);
			$auth = array('user_login'  =>  $nik,
						  'user_access'	=>	$user['department_id'],	
                          'acl'         =>  $user['acl'],  
                          'user_name'   =>  $user['EmployeeNickName'],
                          'user_group'  =>  $user['aclname']);
			$this->session->set_userdata($auth);
			$this->users->userLog($_SERVER['REMOTE_ADDR'],'Login');
			$redirect = "/";
		else:
			$this->session->set_flashdata('error_login','Login Error, Wrong NIK or Password');
			$redirect = "auth/index";
		endif;
		redirect($redirect,301);	
	}
	
	public function do_logout()
    {
        $this->session->sess_destroy();
        redirect("");
    }
}

/* End of file auth.php */
/* Location: ./application/controllers/auth.php */